<?php

class dbaConfigurations {

  function dbaConfigurations (&$dba){
    $this->dba = &$dba;
  }

  function add ($art_id,$name,$descr,$position,$be_null){
    if (!$be_null) $be_null = 'N';
    return $this->dba->query("insert into ".$this->dba->tableforwarder."_shopConfiguration (art_id,name,descr,position,be_null) values ('$art_id','$name','$descr','$position','$be_null');");
  }

  function addConfArt ($conf_id,$art_id){
    return $this->dba->query("insert into ".$this->dba->tableforwarder."_shopConfArt (art_id,conf_id) values ('$art_id','$conf_id');");
  }

  function update ($id,$art_id,$name,$descr,$position,$be_null){
    if (!$be_null) $be_null = 'N';
    return $this->dba->query("update ".$this->dba->tableforwarder."_shopConfiguration set art_id='$art_id',name='$name',descr='$descr',position='$position',be_null='$be_null' where id = $id;");
  }

  function del ($id){
    $this->dba->query("delete from ".$this->dba->tableforwarder."_shopConfArt where conf_id='$id';");
    return $this->dba->query("delete from ".$this->dba->tableforwarder."_shopConfiguration where id='$id';");
  }

  function delConfArt ($id){
    return $this->dba->query("delete from ".$this->dba->tableforwarder."_shopConfArt where id='$id';");
  }

  function getByArticle ($art_id){
    $this->dba->query("select * from ".$this->dba->tableforwarder."_shopConfiguration where art_id = '$art_id' order by position;");
    return $this->dba->fetch_rows_array();
  }

  function getByID ($id){
    $this->dba->query("select * from ".$this->dba->tableforwarder."_shopConfiguration where id = '$id';");
    return $this->dba->fetch_row_array();
  }

  function getArticlesByConf ($id){
     $this->dba->query("select mwst_id,name,orderno,short_descr,amount,".$this->dba->tableforwarder."_shopConfArt.art_id As id,".$this->dba->tableforwarder."_shopConfArt.id As confart_id,kg from ".$this->dba->tableforwarder."_shopArt,".$this->dba->tableforwarder."_shopConfArt where ".$this->dba->tableforwarder."_shopConfArt.conf_id = $id and ".$this->dba->tableforwarder."_shopConfArt.art_id = ".$this->dba->tableforwarder."_shopArt.id order by name;");
     $articles = $this->dba->fetch_rows_array();
     if (!$articles) return;
     for ($i=0;$i<count($articles);$i++){
       $this->dba->query("select satz As tax from ".$this->dba->tableforwarder."_shopmwst where id = '".$articles[$i]['mwst_id']."';");
       $mwst = $this->dba->fetch_row_array();
       $articles[$i]['tax'] = $mwst['tax'];
     }
     return $articles;
  }
}

?>
